#include "ObBackground.h"
#include "D3DApp.h"
#include "Camera.h"

IDirect3DTexture9* ObBackGround::mTex = 0;

ObBackGround::ObBackGround(){
	mID		= 0;
	mInfo	= 0;
	mWidth	= 10.0f;
	mHeight = 10.0f;
	mCenter = D3DXVECTOR3(mWidth/2,mHeight/2,0.0f);
}

ObBackGround::~ObBackGround(){

}

void ObBackGround::update(float dt){

}

void ObBackGround::render(ID3DXSprite* mSprite){
	if(mTex == 0) return;

	D3DXMATRIX S;
	float rate = 100.0f;
	D3DXMatrixScaling(&S,rate,-rate, 0);
	D3DXMATRIX R;
	D3DXMatrixRotationZ(&R, mRotation);
	mSprite->SetTransform(&(S*R));
	RECT rect = calRenderRECT(mSpritePos,mWidth,mHeight);
	mSprite->Draw(mTex,&rect,&mCenter,0,D3DCOLOR_XRGB(255, 255, 255)); 
	mSprite->Flush();
}

bool ObBackGround::loadTexture(){
	if(mTex == 0){
		D3DXCreateTextureFromFileEx(gDevice,"Sprites/Background.png",
			D3DX_DEFAULT_NONPOW2,
			D3DX_DEFAULT_NONPOW2,//D3DX_DEFAULT_NONPOW2
			0,
			0,
			D3DFMT_UNKNOWN,
			D3DPOOL_MANAGED,
			D3DX_DEFAULT,
			D3DX_DEFAULT,
			D3DCOLOR_XRGB(0,0,0),
			NULL,
			NULL,
			&mTex);
		return true;
	}else{
		return false;
	}
}

bool ObBackGround::releaseTexture(){
	if(mTex != 0){
		ReleaseCOM(mTex);
		return true;
	}else{
		return false;
	}
}
